<?php
header('Content-type:text/html;charset=utf8');
/**
 * xysc users Version1.0
 * ==================================
 * Copy 2016-2017
 * Web:www.xjh7.com
 * ==================================
 * Author:lj
 * Date:2016-03-15
*/

/**
 * 
 * 角色控制器
 * @author lj
 *
 */
class RoleController extends Controller{

	
	//访问控制
	function filters(){
		return array(
			'accessControl'
		);
	}
	
	
	function accessRules(){
		
		return array(  
	  /*      array('allow',  // 所有用户有操作权限：index,view  
	            'actions'=>array('index','view'),  
	            'users'=>array('*'),  
	        ),  
	        array('allow', // 仅登录用户有权限操作：create,update  
	            'actions'=>array('create','update'),  
	            'users'=>array('@'),  
	        ),  
	        array('allow', // 指定用户有权限操作：admin,delete  
	            'actions'=>array('admin','delete'),  
	            'users'=>array('admin'),  
	        ),  
	        array('deny',  // 禁止所有用户操作  
	            'users'=>array('*'),  
	        ),  */
		  array('allow', // 仅登录用户有权限操作：create,update  
	            'actions'=>array('create','update'),  
	            'users'=>array('@'),  
	        ),  
	    );  
		
	}
	
	function actionRole(){
		$this->renderPartial('roleTop');
	}
	
	function actionQuery(){
		$role_model = Role::model();
		$info = $role_model->queryRole($_POST['role_name'],$_POST['role_type']);	
		$this->renderPartial('roleList',array('info'=>$info));	
	}
	
	function actionToAdd(){	
		$this->renderPartial('roleAdd');
	}
	/**
	 * 修改界面
	 * @param $page_id
	 */
	function actionUpdate($role_id){	
		$role_model = Role::model();
		$infos = $role_model -> getRoleInfoByRoleId($role_id);
		$infos = $infos[0];
		$this->renderPartial('roleUpdate',array('id'=>$role_id,'infos'=>$infos));
	}
	
	/**
	 * @author xjh
	 * 修改
	 */
	function actionroleUpdate(){
		$role = Role::model();
		$row = $role -> updateRoleByRoleId($_POST['role_id']);
		if($row){
			echo "<script>alert('修改成功');</script>";
			$this->redirect("./index.php?r=backweb/role/role");
		}else{
			echo "修改失败";
		}
	}
	/**
	 * @author xjh
	 * 删除
	 */
	function actionDelete($role_id){
		$role = Role::model();
		$row = $role -> DeleteRoleByRoleId($role_id);
		if($row){
			$this->redirect("./index.php?r=backweb/role/role");
		}else{
			echo "删除失败";
		}
	}
	
	function actionAdd(){	
	
		$role_model = Role::model();
		$result = $role_model->addRole($_POST['role_name'],$_POST['role_type'],$_POST['role_description']);
	 	if($result){
	        	echo "<script>alert('添加成功');</script>";
	        	$this->renderPartial('roleTop');
	    }else{
	        	echo "<script>alert('添加失败');</script>";
	        	$this->renderPartial('roleAdd');
	    }
		
	}
	
	function actionPower($role_id){			
		$role_model = Role::model();
		$info = $role_model->queryRolePower($role_id);
		$this->renderPartial('rolePower',array('info'=>$info,'role_id'=>$role_id));
	}
	/**
	 * 	foreach ($_POST['power'] as $k=>$v){ 
		echo "<script>alert('".$v."');</script>";
			}
	 * @param $role_id
	 */
	function actionUpdatePower($role_id){
		$role_model = Role::model();		
		$info = $role_model->queryUpdatePower($role_id,$_POST['power']);
		
		$this->renderPartial('roleTop');
	}
	
}
?>